using System.Collections;
using System.Collections.Specialized;

namespace SearchTools.Search
{
    /// <summary>
    /// Result object, a name value collection of fields / values with an additonal ranking score
    /// </summary>
    public class Result : NameValueCollection
    {
        private float _Score;

        /// <summary>
        /// Gets or sets the score.
        /// </summary>
        /// <value>The score.</value>
        public float Score
        {
            get { return _Score; }
            set { _Score = value; }
        }
    }


    /// <summary>
    /// List of results
    /// </summary>
    public class ResultCollection : CollectionBase
    {
        private Lucene.Net.Search.Searcher searcher;

        /// <summary>
        /// Creates a new instance of ResultCollection
        /// </summary>
        /// <param name="searcher"></param>
        public ResultCollection(Lucene.Net.Search.Searcher searcher)
        {
            this.searcher = searcher;
        }

        public Result this[int index]
        {
            get { return (Result) List[index]; }
            set { List[index] = value; }
        }


        // public methods...
        public int Add(Result nameValueCollection)
        {
            return List.Add(nameValueCollection);
        }

        #region IndexOf

        public int IndexOf(Result nameValueCollection)
        {
            for (int i = 0; i < List.Count; i++)
                if (this[i] == nameValueCollection) // Found it
                    return i;
            return -1;
        }

        #endregion

        #region Insert

        public void Insert(int index, Result nameValueCollection)
        {
            List.Insert(index, nameValueCollection);
        }

        #endregion

        #region Remove

        public void Remove(Result nameValueCollection)
        {
            List.Remove(nameValueCollection);
        }

        #endregion

        #region Find

        // TODO: If desired, change parameters to Find method to search based on a property of Result.
        public Result Find(Result nameValueCollection)
        {
            foreach (Result lNameValueCollection  in this)
                if (lNameValueCollection == nameValueCollection) // Found it
                    return lNameValueCollection;
            return null; // Not found
        }

        #endregion

        #region Contains

        // TODO: If you changed the parameters to Find (above), change them here as well.
        public bool Contains(Result nameValueCollection)
        {
            return (Find(nameValueCollection) != null);
        }

        #endregion

        // public properties...

        #region this[int aIndex]

        #endregion
    }
}